package com.wshoto.delayed;

import org.redisson.Redisson;
import org.redisson.api.RBlockingQueue;
import org.redisson.api.RDelayedQueue;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;

public class DelayedConsumer {
    public static void main(String[] args) {
        String redisAddress = "redis://120.24.195.35:6379";
        String redisPassword = "Wang103750";
        String queueName = "delayedQueue";
        Config config = new Config();
        config.setCodec(new JsonJacksonCodec());
        config.useSingleServer().setAddress(redisAddress).setPassword(redisPassword)
                .setDatabase(0);
        RedissonClient redissonClient = Redisson.create(config);
        RBlockingQueue<MessageInfo> blockingFairQueue = redissonClient.getBlockingQueue(queueName);
        RDelayedQueue<MessageInfo> delayedQueue = redissonClient.getDelayedQueue(blockingFairQueue);//用于发送
        new Thread(()->{
            try {
                while (true) {
                    MessageInfo message = blockingFairQueue.take();
                    System.out.println(message);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        //redissonClient.shutdown();
    }
}
